from pydantic import BaseModel, ConfigDict, constr
from typing import Optional, List
from datetime import datetime


class UserBase(BaseModel):
    username: str
    email: str


class UserCreate(UserBase):
    hashed_password: str


class User(UserBase):
    id: int
    created_at: datetime
    updated_at: datetime

    # Pydantic model configuration
    model_config = ConfigDict(from_attributes=True)


# 密码复杂度验证（至少8字符，含大小写和特殊字符）
# PasswordStr = constr(
#     min_length=8,
#     pattern=r"^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%^&*]).*$"
# )


class ChangePasswordRequest(BaseModel):
    current_password: str
    new_password: str
    confirm_password: str


class AccountBase(BaseModel):
    account_username: Optional[str] = None
    account_password: Optional[str] = None
    account_email: Optional[str] = None

    description: Optional[str] = None  # 账号描述
    icon_id: Optional[int] = None  # icon id
    tag: Optional[str] = None  # 用来分类
    remark: Optional[str] = None  # 备注

    # Pydantic model configuration
    model_config = ConfigDict(from_attributes=True)


class AccountInfo(AccountBase):
    id: int
    owner_id: int
    create_at: datetime  # 记录创建的时间
    update_at: datetime  # 记录更新的时间

    # Pydantic model configuration
    model_config = ConfigDict(from_attributes=True)


class AccountCreate(AccountBase):
    pass


class AccountUpdate(AccountBase):
    pass


class IconFileBase(BaseModel):
    file_name: str
    file_url: str
    file_size: int  # 文件大小，以字节为单位
    file_type: str  # 文件类型（如：png, jpg等）

    # Pydantic model configuration
    model_config = ConfigDict(from_attributes=True)


class IconFile(IconFileBase):
    id: int
    create_at: datetime  # 记录创建的时间
    update_at: datetime  # 记录更新的时间

    # Pydantic model configuration
    model_config = ConfigDict(from_attributes=True)


class IconFileCreate(IconFileBase):
    pass


class IconFileDelete(IconFileBase):
    pass


class IconFileUpdate(IconFileBase):
    pass
